package com.autocar.reader.adapter;

import java.lang.reflect.Array;
import java.util.ArrayList;

import com.autocar.reader.R;
import com.autocar.reader.bean.SpaceSubBean;
import com.autocar.reader.util.ImageUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatSpaceAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private ArrayList<SpaceSubBean> listItmes;

	public ChatSpaceAdapter(Context context) {
		inflater = LayoutInflater.from(context);
	}

	public void setListItems(ArrayList<SpaceSubBean> listItmes) {
		this.listItmes = listItmes;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return listItmes == null ? 0 : listItmes.size();
	}

	@Override
	public SpaceSubBean getItem(int position) {
		return listItmes.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewHodler;
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.chat_person_space_list_item, null);
			viewHodler = new ViewHodler();
			viewHodler.picIv = (ImageView) convertView
					.findViewById(R.id.chat_person_space_list_item_pic_iv);
			viewHodler.commentTv = (TextView) convertView
					.findViewById(R.id.chat_person_space_list_item_content_tv);
			viewHodler.timeTv = (TextView) convertView
					.findViewById(R.id.chat_person_space_list_item_time_tv);
			convertView.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) convertView.getTag();
		}

		SpaceSubBean bean = getItem(position);
		viewHodler.commentTv.setText(bean.getContent());
		viewHodler.timeTv.setText(bean.getAddtime());
		ImageUtils.fb.display(viewHodler.picIv, bean.getPhoto());
		return convertView;
	}

	class ViewHodler {
		TextView commentTv;
		TextView timeTv;
		ImageView picIv;
	}

}
